import React ,{ Component } from "react";
import axios from "axios";

class ajax extends Component {
  constructor(props) {
    super(props);
    this.state = {
      username: "",
      lastGistUrl: "",
    };
  }
  componentDidMount() {
    axios.get(this.props.source).then((result)=> {
        console.log(result,'数据--------------')
        var lastGist = result[0];
        this.setState({
          username: lastGist.owner.login,
          lastGistUrl: lastGist.html_url,
        });
      }).catch(err=>{
          console.log(err,'err')
      })
  }
  render() {
      console.log(this.props.source,'source')
    return (
      <div>
        {this.state.username}'s last gist is{" "}
        <a href={this.state.lastGistUrl}>here</a>.
      </div>
    );
  }
}
export default ajax;
